package com.ruoyi.quartz.task;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.account.service.IAccountMerchantInfoHisService;
import com.ruoyi.account.service.IAccountProductInfoHisService;
import com.ruoyi.channel.service.IChannelCountInfoService;
import com.ruoyi.channel.service.IChannelCountPvInfoService;
import com.ruoyi.channel.service.IChannelCountUvInfoService;
import com.ruoyi.db.mapper.MerchantDataPushInfoMapper;
import com.ruoyi.laiqianba.service.ISmsRecordInfoService;
import com.ruoyi.merchant.service.IMerchantDataPushInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Component("deleteMerchantPushTask")
public class DeleteMerchantPushTask {

    @Autowired
    IMerchantDataPushInfoService MerchantDataPushInfoService;
    @Autowired
    IAccountMerchantInfoHisService accountMerchantInfoHisService;
    @Autowired
    IAccountProductInfoHisService accountProductInfoHisService;
    @Autowired
    IChannelCountInfoService  channelCountInfoService;
    @Autowired
    IChannelCountPvInfoService channelCountPvInfoService;
    @Autowired
    IChannelCountUvInfoService  channelCountUvInfoService;
    @Autowired
    ISmsRecordInfoService  smsRecordInfoService;
    public void delete(){
        LocalDate today = LocalDate.now();
        String dateInfo = today.minusMonths(3).toString();
        LocalDateTime now = LocalDateTime.now();
        String createTime = now.minusMonths(3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        try {
            int  merchantDataPushNumber = MerchantDataPushInfoService.deleteMerchantDataPushInfoByDateInfo(dateInfo);

            log.info("【定时清理推送日志】,任务执行完毕,一共清理{}条数据", merchantDataPushNumber);

            int  accountMerchantHisNumber =accountMerchantInfoHisService.deleteAccountMerchantHisInfoByDateInfo(dateInfo);
            log.info("【定时清理商户消耗日志】,任务执行完毕,一共清理{}条数据", accountMerchantHisNumber);

            int  accountProductHisNumber =accountProductInfoHisService.deleteAccountProductHisInfoByDateInfo(dateInfo);
            log.info("【定时清理产品消耗日志】,任务执行完毕,一共清理{}条数据", accountProductHisNumber);

            int channelCountNumber = channelCountInfoService.deleteChannelCountInfoByDateInfo(dateInfo);
            log.info("【定时清理渠道统计日志】,任务执行完毕,一共清理{}条数据", channelCountNumber);

            int channelCountPvNumber = channelCountPvInfoService.deleteChannelCountPvInfoByDateInfo(dateInfo);
            log.info("【定时清理渠道pv统计日志】,任务执行完毕,一共清理{}条数据", channelCountPvNumber);

            int channelCountUvNumber = channelCountUvInfoService.deleteChannelCountUvInfoByDateInfo(dateInfo);
            log.info("【定时清理渠道uv统计日志】,任务执行完毕,一共清理{}条数据", channelCountUvNumber);

            int smsNumber =  smsRecordInfoService.deleteSmsRecordInfoByCreateTime(createTime);
            log.info("【定时清理短信发送日志】,任务执行完毕,一共清理{}条数据", smsNumber);
        } catch (Exception e) {
            System.err.println("任务执行失败======"+e);
            throw new RuntimeException(e);
        }

    }
}
